const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()

exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const openid = wxContext.OPENID
  const { roomId, points } = event.data
  return db.collection('point').add({
    data: {
      roomId,
      playerId: openid,
      points,
      color: '#f22',
      lineWidth: 3
    }
  })
}